// Fill out your copyright notice in the Description page of Project Settings.


#include "UI/GameUI/UMG/UI_Inventory.h"

#include "Components/UniformGridPanel.h"
#include "Components/UniformGridSlot.h"
#include "UI/GameUI/UMG/UI_InventorySlot.h"

void UUI_Inventory::NativeConstruct()
{
	Super::NativeConstruct();

	LayoutInventorySlot(3, 7);
}

void UUI_Inventory::LayoutInventorySlot(int32 ColumnNumber, int32 RowNumber)
{
	 if(!InventorySlotClass)
	 	return;

	for (int32 MyColumn = 0; MyColumn < ColumnNumber; MyColumn++)
	{
		for (int MyRow = 0; MyRow < RowNumber; MyRow++)
		{
			if (UUI_InventorySlot* SlotWidget = CreateWidget<UUI_InventorySlot>(GetWorld(), InventorySlotClass))
			{
				if (UUniformGridSlot* GridSlot = SlotArrayInventory->AddChildToUniformGrid(SlotWidget))
				{
					// 设置位置
					GridSlot->SetColumn(MyColumn);
					GridSlot->SetRow(MyRow);
					// 设置填充模式
					GridSlot->SetHorizontalAlignment(HAlign_Fill);
					GridSlot->SetVerticalAlignment(VAlign_Fill);
				}

				InventorySlotArray.Add(SlotWidget);
			}
			
		}

		
	}
	
}
